
<?php 
/*
Template Name: Add product
*/
?>
<?php  ?>
 
<?php 

  if ( !is_user_logged_in() ) 
    {
      ?>

       
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 
get_header();
    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

        
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
     ?>

<div id="content_nano_three" class="clearfix">
    
     <div id="breaum_suausser"><h2>Thêm Máy</h2></div>

		<div id="content" class='edit_user-page_phuc'>

		<div class="wrap">
					<div><br></div><h2 id="add-new-user"> Thêm </h2>
					<p>Tạo máy mới và thêm vào trang này</p>
					<form action="<?php bloginfo('url');?>/process-product" method="POST"  id="creatproduct">
						<input name="id_may" type="hidden" id='id_may' value="createuser">
						<table class="form-table">
							<tbody>
								<tr class="form-field form-required">
								<th scope="row">
									<label Style='font-size:20px;font-weight:bold;'>Tên Máy<span class="description"></span>
									</label>
								</th>
								<td>
									<input name="name_may" type="text" id="name_may" value="" aria-required="true">
								</td>
							</tr>
							<tr class="form-field form-required">
								<?php //print_r($_FILES);?>

							   <div id="main">

									
									<form method="POST" enctype="multipart/form-data" action="<?php echo get_bloginfo('template_directory').'/page-upload.php'?>">
							    		<input type="file" name="images" id="images" multiple />
							    		<button type="submit" id="btn">Upload ảnh</button>
							    	</form>
							    	
                             <script type="text/javascript">
							    (function () {
										var input = document.getElementById("images"), 
											formdata = false;



										function showUploadedItem (source) {
									  		var list = document.getElementById("image-list"),
										  		li   = document.createElement("li"),
										  		img  = document.createElement("img");
									  		img.src = source;
									  		li.appendChild(img);
											list.appendChild(li);
										}   

										if (window.FormData) {
									  		formdata = new FormData();
									  		document.getElementById("btn").style.display = "none";
										}
										
									 	input.addEventListener("change", function (evt) {
									 		document.getElementById("response").innerHTML = "Uploading . . ."
									 		var i = 0, len = this.files.length, img, reader, file;
										
											for ( ; i < len; i++ ) {
												file = this.files[i];
										
												if (!!file.type.match(/image.*/)) {
													if ( window.FileReader ) {
														reader = new FileReader();
														reader.onloadend = function (e) { 
															showUploadedItem(e.target.result, file.fileName);
														};
														reader.readAsDataURL(file);
													}
													//alert(formdata);
													// debugger;
													if (formdata) {
														formdata.append("images[]", file);
													}
												}	
											}

											//alert(formdata);
											//return;
								

												if (formdata) {
													jQuery.ajax({
														url: "<?php bloginfo('url');?>/page_upload",
														type: "POST",
														data: formdata,
														processData: false,
														contentType: false,
														success: function (res) {
															//alert(res);
															document.getElementById("response").innerHTML = res; 
														}
													});
												}
											}, false);
										}());

										</script>
							     	<div id="response"></div>
									<ul id="image-list"></ul>

								</div>
							</tr>
							<!-- 
							<tr class="form-field">
								<th scope="row"><label for="ngay_tao"></label></th>
								<td><input name="ngay_tao" type="hidden" id="ngay_tao" value=""></td>
							</tr>
							<tr class="form-field">
								<th scope="row"><label for="ngay_sua"></label></th>
								<td><input name="ngay_sua" type="hidden" id="ngay_sua" value=""></td>
							</tr>
							-->
							</tbody>
						</table>

						<p class="submit">
							<input type="submit" name="create_may" id="create_may" class="button button-primary" value="Thêm Máy Mới "> 
						</p>
					 </form>
		</div><!-- end class="wrap" --> 
       </div><!--- id="content" -->
</div><!-- id="content_nano_three" -->

<?php 
} //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) )  
 ?>

		
<?php get_footer(); ?>